package crud.client.data;

import java.io.Serializable;

import com.google.gwt.user.client.rpc.IsSerializable;
import com.smartgwt.client.data.Record;

import crud.client.dialog.TableListGrid;

public class Donnee implements Serializable, IsSerializable
{
	private Colonne colonne;
	private DataView dataView = new DataView();

	public Donnee()
	{
		super();
	}
	
	
	public Donnee(Colonne colonne)
	{
		super();
		this.colonne = colonne;
	}


	public Donnee(Colonne colonne, DataView dataView)
	{
		super();
		this.colonne = colonne;
		this.dataView = dataView;
	}
	public Colonne getColonne()
	{
		return colonne;
	}
	public void setColonne(Colonne colonne)
	{
		this.colonne = colonne;
	}
	public void setValueInRecord(final Record record, final TableListGrid tableListGrid)
	{
		getColonne().getFormItemFactory().setValueInRecord(record, tableListGrid, this);
	
		// Sauvegarde de la donnée (pour utilisation ultérieure)
		record.setAttribute(this.getColonne().getCodeColonne() + "-donnee" , this);
	}
	
	public static Donnee extractDonneeFromRecord(Colonne colonne, Record record)
	{
		return (Donnee) record.getAttributeAsObject(colonne.getCodeColonne() + "-donnee");
	}
	
	@Override
	public String toString()
	{
		return this.getColonne().getLibelle() + " - " + this.getDataView().getLabel();
	}


	public DataView getDataView()
	{
		return dataView;
	}


	public void setDataView(DataView dataView)
	{
		this.dataView = dataView;
	}

	
}
